// var i;
// var $bundleConfig = require("./BundleConfig");
// var $uIView = require("./UIView");
// var $uI_PlaerInfo_UIBindings = require("./UI_PlaerInfo_UIBindings");
// var $excel = require("./Excel");
// var $buffMag = require("./BuffMag");
// var f = cc._decorator;
// var g = f.ccclass;
// var _ = f.property;
// var y = f.inspector;
// var m = (function (e) {
//     function t() {
//         var t = (null !== e && e.apply(this, arguments)) || this;
//         t.auto_ui = null;
//         return t;
//     }
//     __extends(t, e);
//     t.prototype._show = function (e) {
//         var t = [];
//         for (var o = 1; o < arguments.length; o++) {
//             t[o - 1] = arguments[o];
//         }
//         var n = e;
//         this.initInfo(n);
//     };
//     t.prototype.initInfo = function (e) {
//         return __awaiter(this, void 0, void 0, function () {
//             var t;
//             var o;
//             var n;
//             var i;
//             var a;
//             var r;
//             var c;
//             var u;
//             var d;
//             var p;
//             var f;
//             var g;
//             return __generator(this, function (s) {
//                 switch (s.label) {
//                     case 0:
//                         t = e.playerInfo.equipLevel;
//                         return [
//                             4,
//                             this._loadRes(
//                                 $bundleConfig.BundleNames.Common,
//                                 "res/player/player" + e.playerId + "_" + (t + 1),
//                                 cc.SpriteFrame
//                             )
//                         ];
//                     case 1:
//                         for (
//                             o = s.sent(),
//                                 this.auto_ui.sp_shuiguoimg.spriteFrame = o,
//                                 n = $buffMag.BuffMgr.playAttackJiaCheng(e, e.sgattack, 1),
//                                 i = $buffMag.BuffMgr.getAttackBaoJi(e, !0),
//                                 a = $buffMag.BuffMgr.playAttackJiaCheng(e, e.sgattackspeed, 2),
//                                 this.auto_ui.txt_attacklb.string = "攻击力:" + n,
//                                 this.auto_ui.txt_attackspeed.string = "攻速:" + a,
//                                 this.auto_ui.txt_baoji.string = "暴击:" + 100 * (e.sgbaojia + i.baojijiacheng) + "%",
//                                 this.auto_ui.txt_baojilv.string = "暴击率:" + 100 * (e.sgbaojilv + i.baojijilv) + "%",
//                                 r = $buffMag.BuffMgr.getPlayerCiTiao(e),
//                                 c = this.auto_ui.scroll_citiao.content,
//                                 (u = c.children).forEach(function (e) {
//                                     e.active = !1;
//                                 }),
//                                 d = 0;
//                             d < r.length;
//                             d++
//                         ) {
//                             p = r[d];
//                             (f = u[d]) || ((f = cc.instantiate(u[0])), c.addChild(f));
//                             f.active = !0;
//                             g = f.children[0].getComponent(cc.RichText);
//                             this.setCiTiaoContent(g, p);
//                         }
//                         return [2];
//                 }
//             });
//         });
//     };
//     t.prototype.setCiTiaoContent = function (e, t) {
//         var o = t.citiaomiaoshu;
//         var n = $excel.Excel.shuiguobuff(t.citiaoshuzhitype);
//         var i = o.split("X");
//         var a = "";
//         for (var r = 0; r < i.length; r++) {
//             var c = i[r];
//             if (n.value[r]) {
//                 a += "<color=#ffffff>" + c + "</c><color=#00ff00>" + n.value[r] + "</color>";
//             } else {
//                 a += "<color=#ffffff>" + c + "</c>";
//             }
//         }
//         a = " <outline color=#000000>" + a + "</outline>";
//         e.string = a;
//     };
//     t.prototype.onCloseView = function () {
//         this._close();
//     };
//     __decorate([_($uI_PlaerInfo_UIBindings.default)], t.prototype, "auto_ui", void 0);
//     return __decorate([g], t);
// })($uIView.default);
// exports.default = m;

// import { BundleNames } from "./BundleConfig";
// import UIView from "./UIView";
// import UI_PlaerInfo_UIBindings from "./UI_PlaerInfo_UIBindings";
// import { Excel } from "./Excel";
// import { BuffMgr } from "./BuffMag";

// const { ccclass, property, inspector } = cc._decorator;

// /** Player Info View Class
//  * 建议名称: PlayerInfoView
//  */
// @ccclass
// export default class UI_PlaerInfo extends UIView {
//     /** Auto-generated UI elements
//      * 建议名称: autoUIElements
//      */
//     @property(UI_PlaerInfo_UIBindings)
//     public auto_ui: UI_PlaerInfo_UIBindings | null = null;

//     /**
//      * Show player info
//      * @param e player data
//      * @param args additional arguments
//      * 建议名称: showPlayerInfo
//      */
//     public _show(e: any, ...args: any[]): void {
//         const n = e;
//         this.initInfo(n);
//     }

//     /**
//      * Initialize player information
//      * @param e player data
//      * 建议名称: initializePlayerInfo
//      */
//     private async initInfo(e: any): Promise<void> {
//         const equipLevel = e.playerInfo.equipLevel;
//         const spriteFrame: cc.SpriteFrame = await this._loadRes(
//             BundleNames.Common,
//             `res/player/player${e.playerId}_${equipLevel + 1}`,
//             cc.SpriteFrame
//         );

//         this.auto_ui!.sp_shuiguoimg.spriteFrame = spriteFrame;

//         const attackPower = BuffMgr.playAttackJiaCheng(e, e.sgattack, 1);
//         const criticalData = BuffMgr.getAttackBaoJi(e, true);
//         const attackSpeed = BuffMgr.playAttackJiaCheng(e, e.sgattackspeed, 2);

//         this.auto_ui!.txt_attacklb.string = `攻击力: ${attackPower}`;
//         this.auto_ui!.txt_attackspeed.string = `攻速: ${attackSpeed}`;
//         this.auto_ui!.txt_baoji.string = `暴击: ${(e.sgbaojia + criticalData.baojijiacheng) * 100}%`;
//         this.auto_ui!.txt_baojilv.string = `暴击率: ${(e.sgbaojilv + criticalData.baojijilv) * 100}%`;

//         const playerBuffs = BuffMgr.getPlayerCiTiao(e);
//         const contentNode = this.auto_ui!.scroll_citiao.content;
//         const contentChildren = contentNode.children;

//         contentChildren.forEach((child: cc.Node) => {
//             child.active = false;
//         });

//         for (let i = 0; i < playerBuffs.length; i++) {
//             const buff = playerBuffs[i];
//             let itemNode = contentChildren[i];

//             if (!itemNode) {
//                 itemNode = cc.instantiate(contentChildren[0]);
//                 contentNode.addChild(itemNode);
//             }

//             itemNode.active = true;
//             const richText = itemNode.children[0].getComponent(cc.RichText);
//             this.setCiTiaoContent(richText, buff);
//         }
//     }

//     /**
//      * Set the description for a buff
//      * @param component RichText component to set the description
//      * @param buff Buff data
//      * 建议名称: setBuffDescription
//      */
//     private setCiTiaoContent(component: cc.RichText, buff: any): void {
//         const description = buff.citiaomiaoshu;
//         const buffValues = Excel.shuiguobuff(buff.citiaoshuzhitype);
//         const descriptionParts = description.split("X");
//         let formattedDescription = "";

//         for (let i = 0; i < descriptionParts.length; i++) {
//             const part = descriptionParts[i];
//             if (buffValues.value[i]) {
//                 formattedDescription += `<color=#ffffff>${part}</c><color=#00ff00>${buffValues.value[i]}</color>`;
//             } else {
//                 formattedDescription += `<color=#ffffff>${part}</c>`;
//             }
//         }

//         formattedDescription = `<outline color=#000000>${formattedDescription}</outline>`;
//         component.string = formattedDescription;
//     }

//     /**
//      * Close the view
//      * 建议名称: closeView
//      */
//     public onCloseView(): void {
//         this._close();
//     }
// }

import { BundleNames } from "./BundleConfig";
import UIViewBase from "./UIView";
import UIPlaerInfoUIBindings from "./UI_PlaerInfo_UIBindings";
import { Excel } from "./Excel";
import { BuffMgr } from "./BuffMag";

const { ccclass, property, inspector } = cc._decorator;

/** Player Info View Class
 * 建议名称: PlayerInfoView
 */
@ccclass
export default class ViewPlaerInfo extends UIViewBase {
    /** Auto-generated UI elements
     * 建议名称: autoUIElements
     */
    @property(UIPlaerInfoUIBindings)
    public auto_ui: UIPlaerInfoUIBindings | null = null;

    /**
     * Show player info
     * @param e player data
     * @param args additional arguments
     * 建议名称: showPlayerInfo
     */
    public _show(e: any, ...args: any[]): void {
        this.initializePlayerInfo(e);
    }

    /**
     * Initialize player information
     * @param e player data
     * 建议名称: initializePlayerInfo
     */
    private async initializePlayerInfo(playerData: any): Promise<void> {
        const equipLevel = playerData.playerInfo.equipLevel;
        const spriteFrame: cc.SpriteFrame = await this._loadRes(
            BundleNames.Common,
            `res/player/player${playerData.playerId}_${equipLevel + 1}`,
            cc.SpriteFrame
        );

        this.auto_ui!.sp_shuiguoimg.spriteFrame = spriteFrame;

        const attackPower = BuffMgr.applyAttackBonus(playerData, playerData.sgattack, 1);
        const criticalData = BuffMgr.getAttackCritical(playerData, true);
        const attackSpeed = BuffMgr.applyAttackBonus(playerData, playerData.sgattackspeed, 2);

        this.auto_ui!.txt_attacklb.string = `攻击力: ${attackPower}`;
        this.auto_ui!.txt_attackspeed.string = `攻速: ${attackSpeed}`;
        this.auto_ui!.txt_baoji.string = `暴击: ${(playerData.sgbaojia + criticalData.baojijiacheng) * 100}%`;
        this.auto_ui!.txt_baojilv.string = `暴击率: ${(playerData.sgbaojilv + criticalData.baojijilv) * 100}%`;

        this.updateBuffList(playerData);
    }

    /**
     * Update the buff list on the view
     * @param playerData player data
     * 建议名称: updateBuffList
     */
    private updateBuffList(playerData: any): void {
        const playerBuffs = BuffMgr.getPlayerCiTiaoList(playerData);
        const contentNode = this.auto_ui!.scroll_citiao.content;
        const contentChildren = contentNode.children;

        contentChildren.forEach((child: cc.Node) => {
            child.active = false;
        });

        for (let i = 0; i < playerBuffs.length; i++) {
            const buff = playerBuffs[i];
            let itemNode = contentChildren[i];

            if (!itemNode) {
                itemNode = cc.instantiate(contentChildren[0]);
                contentNode.addChild(itemNode);
            }

            itemNode.active = true;
            const richText = itemNode.children[0].getComponent(cc.RichText);
            this.setBuffDescription(richText, buff);
        }
    }

    /**
     * Set the description for a buff
     * @param component RichText component to set the description
     * @param buff Buff data
     * 建议名称: setBuffDescription
     */
    private setBuffDescription(component: cc.RichText, buff: any): void {
        const description = buff.citiaomiaoshu;
        const buffValues = Excel.shuiguobuff(buff.citiaoshuzhitype);
        const descriptionParts = description.split("X");
        let formattedDescription = "";

        for (let i = 0; i < descriptionParts.length; i++) {
            const part = descriptionParts[i];
            if (buffValues.value[i]) {
                formattedDescription += `<color=#ffffff>${part}</c><color=#00ff00>${buffValues.value[i]}</color>`;
            } else {
                formattedDescription += `<color=#ffffff>${part}</c>`;
            }
        }

        formattedDescription = `<outline color=#000000>${formattedDescription}</outline>`;
        component.string = formattedDescription;
    }

    /**
     * Close the view
     * 建议名称: closeView
     */
    public onCloseView(): void {
        this._close();
    }
}